from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-18 14:15:08.248047
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 18, Oct, 2022
Time: 14:15:14
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.7438
Nobs: 813.000 HQIC: -51.0644
Log likelihood: 10546.5 FPE: 5.44829e-23
AIC: -51.2642 Det(Omega_mle): 4.88064e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.294555 0.052440 5.617 0.000
L1.Burgenland 0.109059 0.035326 3.087 0.002
L1.Kärnten -0.106353 0.018810 -5.654 0.000
L1.Niederösterreich 0.210723 0.073882 2.852 0.004
L1.Oberösterreich 0.100972 0.070865 1.425 0.154
L1.Salzburg 0.250227 0.037622 6.651 0.000
L1.Steiermark 0.037569 0.049252 0.763 0.446
L1.Tirol 0.106547 0.039950 2.667 0.008
L1.Vorarlberg -0.058685 0.034350 -1.708 0.088
L1.Wien 0.059797 0.063192 0.946 0.344
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.062050 0.108485 0.572 0.567
L1.Burgenland -0.033610 0.073080 -0.460 0.646
L1.Kärnten 0.047818 0.038913 1.229 0.219
L1.Niederösterreich -0.171953 0.152843 -1.125 0.261
L1.Oberösterreich 0.386136 0.146602 2.634 0.008
L1.Salzburg 0.286352 0.077831 3.679 0.000
L1.Steiermark 0.105040 0.101889 1.031 0.303
L1.Tirol 0.313873 0.082645 3.798 0.000
L1.Vorarlberg 0.025539 0.071061 0.359 0.719
L1.Wien -0.014717 0.130729 -0.113 0.910
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189257 0.026916 7.031 0.000
L1.Burgenland 0.090203 0.018132 4.975 0.000
L1.Kärnten -0.008404 0.009655 -0.871 0.384
L1.Niederösterreich 0.264707 0.037921 6.980 0.000
L1.Oberösterreich 0.126978 0.036373 3.491 0.000
L1.Salzburg 0.047722 0.019310 2.471 0.013
L1.Steiermark 0.016667 0.025279 0.659 0.510
L1.Tirol 0.094486 0.020505 4.608 0.000
L1.Vorarlberg 0.059420 0.017631 3.370 0.001
L1.Wien 0.119961 0.032434 3.699 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109676 0.027566 3.979 0.000
L1.Burgenland 0.044277 0.018570 2.384 0.017
L1.Kärnten -0.016113 0.009888 -1.630 0.103
L1.Niederösterreich 0.192957 0.038837 4.968 0.000
L1.Oberösterreich 0.294165 0.037251 7.897 0.000
L1.Salzburg 0.115276 0.019777 5.829 0.000
L1.Steiermark 0.099613 0.025890 3.848 0.000
L1.Tirol 0.116395 0.021000 5.543 0.000
L1.Vorarlberg 0.070669 0.018057 3.914 0.000
L1.Wien -0.027326 0.033218 -0.823 0.411
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125337 0.050109 2.501 0.012
L1.Burgenland -0.051553 0.033755 -1.527 0.127
L1.Kärnten -0.040367 0.017974 -2.246 0.025
L1.Niederösterreich 0.170177 0.070597 2.411 0.016
L1.Oberösterreich 0.138905 0.067714 2.051 0.040
L1.Salzburg 0.284388 0.035950 7.911 0.000
L1.Steiermark 0.033019 0.047062 0.702 0.483
L1.Tirol 0.165198 0.038173 4.328 0.000
L1.Vorarlberg 0.104524 0.032823 3.185 0.001
L1.Wien 0.072391 0.060383 1.199 0.231
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060381 0.039655 1.523 0.128
L1.Burgenland 0.038770 0.026713 1.451 0.147
L1.Kärnten 0.050786 0.014224 3.570 0.000
L1.Niederösterreich 0.225551 0.055869 4.037 0.000
L1.Oberösterreich 0.282790 0.053588 5.277 0.000
L1.Salzburg 0.051156 0.028450 1.798 0.072
L1.Steiermark -0.007996 0.037244 -0.215 0.830
L1.Tirol 0.149482 0.030209 4.948 0.000
L1.Vorarlberg 0.070957 0.025975 2.732 0.006
L1.Wien 0.079094 0.047786 1.655 0.098
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175875 0.047422 3.709 0.000
L1.Burgenland -0.005799 0.031946 -0.182 0.856
L1.Kärnten -0.061120 0.017010 -3.593 0.000
L1.Niederösterreich -0.083477 0.066812 -1.249 0.212
L1.Oberösterreich 0.193305 0.064084 3.016 0.003
L1.Salzburg 0.056867 0.034022 1.671 0.095
L1.Steiermark 0.229413 0.044539 5.151 0.000
L1.Tirol 0.494548 0.036127 13.689 0.000
L1.Vorarlberg 0.049826 0.031063 1.604 0.109
L1.Wien -0.047341 0.057145 -0.828 0.407
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161749 0.054403 2.973 0.003
L1.Burgenland -0.011376 0.036648 -0.310 0.756
L1.Kärnten 0.065936 0.019514 3.379 0.001
L1.Niederösterreich 0.200513 0.076647 2.616 0.009
L1.Oberösterreich -0.060548 0.073517 -0.824 0.410
L1.Salzburg 0.216326 0.039030 5.542 0.000
L1.Steiermark 0.113249 0.051095 2.216 0.027
L1.Tirol 0.077315 0.041445 1.865 0.062
L1.Vorarlberg 0.124628 0.035636 3.497 0.000
L1.Wien 0.114224 0.065557 1.742 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.353269 0.031704 11.143 0.000
L1.Burgenland 0.005749 0.021357 0.269 0.788
L1.Kärnten -0.023607 0.011372 -2.076 0.038
L1.Niederösterreich 0.223974 0.044667 5.014 0.000
L1.Oberösterreich 0.175300 0.042843 4.092 0.000
L1.Salzburg 0.047432 0.022745 2.085 0.037
L1.Steiermark -0.016735 0.029776 -0.562 0.574
L1.Tirol 0.109050 0.024152 4.515 0.000
L1.Vorarlberg 0.073765 0.020767 3.552 0.000
L1.Wien 0.053014 0.038204 1.388 0.165
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041758 0.153558 0.190027 0.159184 0.124756 0.115218 0.066007 0.226965
Kärnten 0.041758 1.000000 -0.002167 0.129837 0.042225 0.096074 0.429693 -0.052917 0.101235
Niederösterreich 0.153558 -0.002167 1.000000 0.336833 0.155847 0.300563 0.112215 0.184120 0.328003
Oberösterreich 0.190027 0.129837 0.336833 1.000000 0.231969 0.332488 0.172713 0.172519 0.262735
Salzburg 0.159184 0.042225 0.155847 0.231969 1.000000 0.146340 0.129054 0.149388 0.134345
Steiermark 0.124756 0.096074 0.300563 0.332488 0.146340 1.000000 0.153741 0.141034 0.078995
Tirol 0.115218 0.429693 0.112215 0.172713 0.129054 0.153741 1.000000 0.115447 0.155117
Vorarlberg 0.066007 -0.052917 0.184120 0.172519 0.149388 0.141034 0.115447 1.000000 0.007264
Wien 0.226965 0.101235 0.328003 0.262735 0.134345 0.078995 0.155117 0.007264 1.000000